package xworker.gluon.attach.barcodescan;

import com.gluonhq.attach.barcodescan.BarcodeScanService;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.lang.executor.Executor;

public class BarcodeScanServiceActions {
    private static final String TAG = BarcodeScanServiceActions.class.getName();

    public static String scan(ActionContext actionContext){
        Thing self = actionContext.getObject("self");
        String title = self.doAction("getTitle", actionContext);
        String legend = self.doAction("getLegend", actionContext);
        String resultText = self.doAction("getResultText", actionContext);

        BarcodeScanService service = BarcodeScanService.create().orElse(null);
        if(service != null){
            return service.scan(title, legend, resultText).orElse(null);
        }else{
            Executor.warn(TAG, "BarcodeScanService is null.");
        }

        return null;
    }
}
